package com.wnhz.wnmap.audit.service.impl;

import com.wnhz.wnmap.audit.dao.IAuditDao;
import com.wnhz.wnmap.audit.service.IAuditService;
import com.wnhz.wnmap.domain.entity.Audit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AuditServiceImpl implements IAuditService {
    @Autowired
    private IAuditDao auditDao;
    @Override
    public void reduceSeats(long auditId, int seats) {
        Audit audit = auditDao.selectById(auditId);
        int realSeats = audit.getSeats();
        if((realSeats - seats)>=0 ){
            audit.setSeats(realSeats - seats);
            auditDao.updateById(audit);
            log.debug("预定座位数: {}",seats );
        }else{
            throw  new RuntimeException("本厅的座位已经销售一空，请选择其它影厅");
        }

    }
}
